<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.ParseException" %>
<%@ page import="java.util.Date" %>
<%@ page import="com.wzy.Jdbc封装.pojo.News_detail" %>
<%@ page import="org.apache.commons.fileupload.servlet.ServletFileUpload" %>
<%@ page import="java.io.File" %>
<%@ page import="org.apache.commons.fileupload.disk.DiskFileItemFactory" %>
<%@ page import="org.apache.commons.fileupload.FileItemFactory" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="org.apache.commons.fileupload.FileItem" %>
<jsp:useBean id="detail" class="com.wzy.level.detail.detailDaoImpl.detailDaoImpl"/>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
  <head>
    <title>Title</title>
  </head>
  <body>
<%--  <%--%>
<%--    request.setCharacterEncoding("utf-8");--%>

<%--//    int id = Integer.parseInt(request.getParameter("id"));--%>
<%--//    int categoryId = Integer.parseInt(request.getParameter("categoryId").trim());--%>
<%--//    String title = request.getParameter("title");--%>
<%--//    String summary = request.getParameter("summary");--%>
<%--//    String content = request.getParameter("content");--%>
<%--    int id =0;--%>
<%--    int categoryId =0;--%>
<%--    String title =null;--%>
<%--    String summary =null;--%>
<%--    String content =null;--%>
<%--    String author =null;--%>
<%--    String screateDate =null;--%>
<%--    String smodifyDate =null;--%>

<%--    int state =0;--%>
<%--    //picPath--%>
<%--    //上传图片--%>
<%--    boolean isMultipartFile = ServletFileUpload.isMultipartContent(request);--%>
<%--    String path = "D:\\web_project\\src\\main\\webapp\\images";--%>
<%--    String pa = "http://localhost:8080/images/";--%>
<%--    File o_file = new File(path);--%>

<%--    String picPath = null;--%>
<%--    if(!o_file.exists()){--%>
<%--      o_file.mkdir();--%>
<%--    }--%>

<%--    if(isMultipartFile){--%>
<%--      FileItemFactory fileItemFactory = new DiskFileItemFactory();--%>
<%--      ServletFileUpload servletFileUpload = new ServletFileUpload(fileItemFactory);--%>
<%--//      String charset  =  request.getCharacterEncoding();--%>
<%--//      if  (charset  !=   null ) {--%>
<%--//        servletFileUpload.setHeaderEncoding(charset);--%>
<%--//      }--%>
<%--      List<FileItem> list = servletFileUpload.parseRequest(request);--%>
<%--      Iterator<FileItem> iterator = list.iterator();--%>
<%--      while(iterator.hasNext()){--%>
<%--        FileItem item = iterator.next();--%>
<%--        boolean formField = item.isFormField();--%>
<%--        if(!formField){--%>
<%--          String fileUpdate = item.getName();--%>
<%--          File m_file = new File(fileUpdate);--%>
<%--          if(m_file.getName()!=null && !(m_file.getName().equals(""))){--%>
<%--            File file = new File(path + "\\" + m_file.getName());--%>
<%--            item.write(file);--%>
<%--            System.out.println(file.getPath());--%>
<%--            picPath =pa+file.getName();--%>
<%--            System.out.println(picPath);--%>
<%--          }--%>
<%--        }else {--%>
<%--          String fieldName = item.getFieldName();--%>
<%--          if(fieldName.equals("id")){--%>
<%--            id = Integer.parseInt(item.getString());--%>
<%--          }else if(fieldName.equals("categoryId")){--%>
<%--            categoryId = Integer.parseInt(item.getString().trim());--%>
<%--          }else if(fieldName.equals("title")){--%>
<%--//            title = item.getString();--%>
<%--            title = new String((item.getString("iso8859-1")).getBytes("iso8859-1"),"utf-8");--%>
<%--          }else if(fieldName.equals("summary")){--%>
<%--//           summary = item.getString();--%>
<%--            summary = new String((item.getString("iso8859-1")).getBytes("iso8859-1"),"utf-8");--%>
<%--          }else if(fieldName.equals("content")){--%>
<%--//            content = item.getString();--%>
<%--            content = new String((item.getString("iso8859-1")).getBytes("iso8859-1"),"utf-8");--%>
<%--          }else if(fieldName.equals("author")){--%>
<%--//            author = item.getString();--%>
<%--            author = new String((item.getString("iso8859-1")).getBytes("iso8859-1"),"utf-8");--%>
<%--          }else if(fieldName.equals("date")){--%>
<%--            screateDate = item.getString();--%>
<%--          }else if(fieldName.equals("date1")){--%>
<%--            smodifyDate = item.getString();--%>
<%--          }else if(fieldName.equals("state")){--%>
<%--            state = Integer.parseInt(item.getString());--%>
<%--          }--%>
<%--        }--%>
<%--      }--%>
<%--    }--%>

<%--    //上传结束--%>

<%--    Date createDate = null;--%>
<%--    Date modifyDate = null;--%>
<%--    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-mm-dd");--%>
<%--    try {--%>
<%--      createDate = simpleDateFormat.parse(screateDate);--%>
<%--      modifyDate = simpleDateFormat.parse(smodifyDate);--%>
<%--    }catch (ParseException e){--%>
<%--      e.printStackTrace();--%>
<%--    }--%>

<%--    News_detail news_detail = new News_detail();--%>


<%--//    URLEncoder.encode(picPath,"utf-8");--%>
<%--//    new String(picPath.getBytes(StandardCharsets.UTF_8));--%>

<%--//    title.getBytes(StandardCharsets.UTF_8);--%>

<%--    news_detail.setCategoryId(categoryId);--%>
<%--    news_detail.setTitle(title);--%>
<%--    news_detail.setSummary(summary);--%>
<%--    news_detail.setContent(content);--%>
<%--    news_detail.setPicPath(picPath);--%>
<%--    news_detail.setAuthor(author);--%>
<%--    news_detail.setDate(createDate);--%>
<%--    news_detail.setDate1(modifyDate);--%>



<%--//    String sstate = request.getParameter("state");--%>
<%--//    int state = Integer.parseInt(sstate);--%>


<%--    if(state==0){--%>
<%--      news_detail.setId(id);--%>
<%--      int update = detail.update(news_detail);--%>
<%--      request.setAttribute("update",update);--%>
<%--  }else if(state == 1){--%>
<%--    int insert = detail.insert(news_detail);--%>
<%--    request.setAttribute("insert",insert);--%>
<%--    }--%>
<%--  %>--%>

<%--<c:if test="${update > 0}" >--%>
<%--  <%response.sendRedirect(request.getContextPath()+"/pageManage.jsp");%>--%>
<%--</c:if>--%>
<%--  <c:if test="${update <= 0}" >--%>
<%--    <c:out value="修改失败"></c:out>--%>
<%--  </c:if>--%>
<%--  <c:if test="${insert > 0}" >--%>
<%--  <%response.sendRedirect(request.getContextPath()+"/pageManage.jsp");%>--%>
<%--  </c:if>--%>
<%--  <c:if test="${insert <= 0}" >--%>
<%--    <c:out value="新增失败"></c:out>--%>
<%--  </c:if>--%>
  </body>
</html>
